<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.smartaccounting.util.DatabaseUtil" %>
<%@ page import="java.sql.Connection" %>
<!DOCTYPE html>
<html>
<head>
  <title>数据库测试</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
  <h1>数据库连接测试</h1>

  <%
    try (Connection conn = DatabaseUtil.getConnection()) {
      if (conn != null && !conn.isClosed()) {
  %>
  <div class="alert alert-success">
    <h4>✅ 数据库连接成功！</h4>
    <p>连接信息：<%= conn.getMetaData().getURL() %></p>
  </div>
  <%
    }
  } catch (Exception e) {
  %>
  <div class="alert alert-danger">
    <h4>❌ 数据库连接失败</h4>
    <p>错误信息：<%= e.getMessage() %></p>
    <p>请检查：</p>
    <ul>
      <li>MySQL服务是否启动</li>
      <li>数据库名是否正确：smart_accounting</li>
      <li>用户名密码是否正确</li>
      <li>数据库是否已创建</li>
    </ul>
  </div>
  <%
    }
  %>

  <a href="/test30_war/index.jsp" class="btn btn-primary">返回首页</a>
</div>
</body>
</html>